from django.contrib.auth.models import User
from django.db import models

# Create your models here.
from utils.modelsMixin import ModelSetMixin
from work.models import Label


class Article(ModelSetMixin):
    STATUS_CHOICES = (
        (0, '未发布'),
        (1, '发布')
    )
    title = models.CharField(max_length=100, verbose_name='标题')
    digest = models.CharField(max_length=300, verbose_name='摘要')
    content = models.TextField(verbose_name='文章内容')
    page_view = models.IntegerField(verbose_name='浏览量', default=0)
    priority = models.IntegerField(verbose_name='优先级', default=0)
    status = models.IntegerField(verbose_name='状态', default=0, choices=STATUS_CHOICES)

    label = models.ForeignKey(Label, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        ordering = ['-priority', '-page_view', '-create_time']
        db_table = 'article'
        verbose_name = '文章'
        verbose_name_plural = verbose_name

    def __str__(self):
        return f'{self.id},{self.title}'


class Comment(ModelSetMixin):
    content = models.TextField(verbose_name='评论内容')
    level = models.IntegerField(verbose_name='评论等级', default=1)
    parent_comment = models.IntegerField(verbose_name='父级评论', null=True)
    reply_comment = models.IntegerField(verbose_name='回复评论', null=True)

    article = models.ForeignKey(Article, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        ordering = ['-create_time']
        db_table = 'comment'
        verbose_name = '评论'
        verbose_name_plural = verbose_name



